﻿using Coolzon.UI.Core.Parts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace Coolzon.UI.Core.Runtime.Script.Animation
{
    public class ShowAnimationScriptObject : AnimationScriptObject
    {
        public ShowAnimationScriptObject()
            : base(0)
        {
        }

        public override void AppendToStoryboard(Widget instance, ref double duration, Storyboard storyboard)
        {
            PropertyValueKeeper.Instance.Save(instance, UIElement.VisibilityProperty, instance.Visibility);

            System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames frames = new ObjectAnimationUsingKeyFrames();

            System.Windows.Media.Animation.DiscreteObjectKeyFrame keyFrame = new System.Windows.Media.Animation.DiscreteObjectKeyFrame(System.Windows.Visibility.Visible);
            keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            frames.KeyFrames.Add(keyFrame);
            frames.BeginTime = TimeSpan.FromSeconds(duration);

            Storyboard.SetTarget(frames, instance);
            Storyboard.SetTargetProperty(frames, new System.Windows.PropertyPath(UIElement.VisibilityProperty));

            storyboard.Children.Add(frames);
        }
    }
}
